package constellation.adapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import constellation.custom.DLRoundImageView;
import constellation.util.AssetsUtil;
import constellation.util.StartInfo;

import android.widget.TextView;

import com.example.myapplication.R;

public class ItemDialogGridviewAdapter extends BaseAdapter {

    Context context;
    List<StartInfo.StarinfoBean>mDatas;
    private LayoutInflater layoutInflater;

    public ItemDialogGridviewAdapter(Context context, List<StartInfo.StarinfoBean> mDatas) {
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
        this.mDatas=mDatas;
    }

    @Override
    public int getCount() {
        return mDatas.size();  //返回条目的数量
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);  //返回指定位置上对应的元素
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.item_dialog_gridview, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);

    }else {
        holder = (ViewHolder) convertView.getTag();
    }
//        获取指定位置的数据
        StartInfo.StarinfoBean bean = mDatas.get(position);
        holder.itemLdialogTv.setText(bean.getName()); //获取到星座名，设置到指定的TextView上
        String logoname = bean.getLogoname();
//        将图片所在的文件的整体路径名设置好
//        String filename = "xzcontentlogo/"+logoname+".png";
//        Bitmap bitmap = AssetsUtil.getBitmapByAssets(context, filename); //将图片转换成bitmap
        Map<String, Bitmap> contentlogoImgMap = AssetsUtil.getContentlogoImgMap();
        Bitmap bitmap = contentlogoImgMap.get(logoname);
//        将bitmap设置给imageview
        holder.itemdialogIv.setImageBitmap(bitmap);
        return convertView;
    }



    protected class ViewHolder {
        private DLRoundImageView itemdialogIv;
    private TextView itemLdialogTv;

        public ViewHolder(View view) {
            itemdialogIv = (DLRoundImageView) view.findViewById(R.id.item_dialog_iv);
            itemLdialogTv = (TextView) view.findViewById(R.id.item_dialog_tv);
        }
    }
}
